#### GROUP-LEVEL PREDICTORS? START WITH DISTANCE ITSELF

# DV: INTOLERANCE

ri.gl.state.i <- lmer(intolerance~gpc.Distance + gpc.prop_jewish25+gpc.unemployment33+gpc.population25+gpc.nazishare33 + 
                        MeanDistanceS +
                        ( 1 | state) ,evs,
                      control = lmerControl(optimizer ="Nelder_Mead"))
ri.gl.camp.i <- lmer(intolerance~gpc.Distance + gpc.prop_jewish25+gpc.unemployment33+gpc.population25+gpc.nazishare33 + 
                       MeanDistanceC +
                       ( 1 | closest_camp) ,evs,
                     control = lmerControl(optimizer ="Nelder_Mead"))
ri.gl.state.camp.i <- lmer(intolerance~gpc.Distance + gpc.prop_jewish25+gpc.unemployment33+gpc.population25+gpc.nazishare33 + 
                             MeanDistanceS + MeanDistanceC +
                             ( 1 | state) + ( 1 | closest_camp) ,evs,
                           control = lmerControl(optimizer ="Nelder_Mead"))
gl.state.camp.i <- lm(intolerance~gpc.Distance + gpc.prop_jewish25+gpc.unemployment33+gpc.population25+gpc.nazishare33 + 
                        MeanDistanceS + MeanDistanceC,data=evs)
gl.state.i <- lm(intolerance~gpc.Distance + gpc.prop_jewish25+gpc.unemployment33+gpc.population25+gpc.nazishare33 + 
                   MeanDistanceS , data=evs)
gl.camp.i <- lm(intolerance~gpc.Distance + gpc.prop_jewish25+gpc.unemployment33+gpc.population25+gpc.nazishare33 + 
                  MeanDistanceC, data=evs)
tab_model(ri.gl.state.i,ri.gl.camp.i,ri.gl.state.camp.i,gl.state.i,gl.camp.i, gl.state.camp.i,
          show.se=TRUE, show.ci=FALSE, collapse.se=TRUE, show.p=FALSE, p.style="asterisk", p.threshold = c(0.05, 0.01),
          file="tableS8.html")


# DV: RESENTMENT

ri.gl.state.r <- lmer(resentment~gpc.Distance + gpc.prop_jewish25+gpc.unemployment33+gpc.population25+gpc.nazishare33 + 
                        MeanDistanceS +
                        ( 1 | state) ,evs,
                      control = lmerControl(optimizer ="Nelder_Mead"))
ri.gl.camp.r <- lmer(resentment~gpc.Distance + gpc.prop_jewish25+gpc.unemployment33+gpc.population25+gpc.nazishare33 + 
                       MeanDistanceC +
                       ( 1 | closest_camp) ,evs,
                     control = lmerControl(optimizer ="Nelder_Mead"))
ri.gl.state.camp.r <- lmer(resentment~gpc.Distance + gpc.prop_jewish25+gpc.unemployment33+gpc.population25+gpc.nazishare33 + 
                             MeanDistanceS + MeanDistanceC +
                             ( 1 | state) + ( 1 | closest_camp) ,evs,
                           control = lmerControl(optimizer ="Nelder_Mead"))
gl.state.camp.r <- lm(resentment~gpc.Distance + gpc.prop_jewish25+gpc.unemployment33+gpc.population25+gpc.nazishare33 + 
                        MeanDistanceS + MeanDistanceC ,data=evs)
gl.state.r <- lm(resentment~gpc.Distance + gpc.prop_jewish25+gpc.unemployment33+gpc.population25+gpc.nazishare33 + 
                   MeanDistanceS, data=evs)
gl.camp.r <- lm(resentment~gpc.Distance + gpc.prop_jewish25+gpc.unemployment33+gpc.population25+gpc.nazishare33 + 
                  MeanDistanceC, data=evs)
tab_model(ri.gl.state.r,ri.gl.camp.r,ri.gl.state.camp.r,gl.state.r,gl.camp.r, gl.state.camp.r,
          show.se=TRUE, show.ci=FALSE, collapse.se=TRUE, show.p=FALSE, p.style="asterisk", p.threshold = c(0.05, 0.01),
          file="tableS9.html")


# DV: FAR-RIGHT

ri.gl.state.f <- lmer(far_right~gpc.Distance + gpc.prop_jewish25+gpc.unemployment33+gpc.population25+gpc.nazishare33 + 
                        MeanDistanceS +
                        ( 1 | state) ,evs,
                      control = lmerControl(optimizer ="Nelder_Mead"))
ri.gl.camp.f <- lmer(far_right~gpc.Distance + gpc.prop_jewish25+gpc.unemployment33+gpc.population25+gpc.nazishare33 + 
                       MeanDistanceC +
                       ( 1 | closest_camp) ,evs,
                     control = lmerControl(optimizer ="Nelder_Mead"))
ri.gl.state.camp.f <- lmer(far_right~gpc.Distance + gpc.prop_jewish25+gpc.unemployment33+gpc.population25+gpc.nazishare33 + 
                             MeanDistanceS + MeanDistanceC +
                             ( 1 | state) + ( 1 | closest_camp) ,evs,
                           control = lmerControl(optimizer ="Nelder_Mead"))
gl.state.camp.f <- lm(far_right~gpc.Distance + gpc.prop_jewish25+gpc.unemployment33+gpc.population25+gpc.nazishare33 + 
                        MeanDistanceS + MeanDistanceC ,data=evs)
gl.state.f <- lm(far_right~gpc.Distance + gpc.prop_jewish25+gpc.unemployment33+gpc.population25+gpc.nazishare33 + 
                   MeanDistanceS, data=evs)
gl.camp.f <- lm(far_right~gpc.Distance + gpc.prop_jewish25+gpc.unemployment33+gpc.population25+gpc.nazishare33 + 
                  MeanDistanceC, data=evs)
tab_model(ri.gl.state.f,ri.gl.camp.f,ri.gl.state.camp.f,gl.state.f,gl.camp.f, gl.state.camp.f,
          show.se=TRUE, show.ci=FALSE, collapse.se=TRUE, show.p=FALSE, p.style="asterisk", p.threshold = c(0.05, 0.01),
          file="tableS10.html")



#### GROUP-LEVEL PREDICTORS? WHERE ARE THE JEWS? NOT THE PROBLEM (NOT REPORTED)

# DV: INTOLERANCE

ri.gl.state.i <- lmer(intolerance~gpc.Distance + gpc.prop_jewish25+gpc.unemployment33+gpc.population25+gpc.nazishare33 + 
                        MeanJewsS +
                        ( 1 | state) ,evs,
                      control = lmerControl(optimizer ="Nelder_Mead"))
ri.gl.camp.i <- lmer(intolerance~gpc.Distance + gpc.prop_jewish25+gpc.unemployment33+gpc.population25+gpc.nazishare33 + 
                       MeanJewsC +
                       ( 1 | closest_camp) ,evs,
                     control = lmerControl(optimizer ="Nelder_Mead"))
ri.gl.state.camp.i <- lmer(intolerance~gpc.Distance + gpc.prop_jewish25+gpc.unemployment33+gpc.population25+gpc.nazishare33 + 
                             MeanJewsS + MeanJewsC +
                             ( 1 | state) + ( 1 | closest_camp) ,evs,
                           control = lmerControl(optimizer ="Nelder_Mead"))
gl.state.camp.i <- lm(intolerance~gpc.Distance + gpc.prop_jewish25+gpc.unemployment33+gpc.population25+gpc.nazishare33 + 
                        MeanJewsS + MeanJewsC ,data=evs)
gl.state.i <- lm(intolerance~gpc.Distance + gpc.prop_jewish25+gpc.unemployment33+gpc.population25+gpc.nazishare33 + 
                   MeanJewsS, data=evs)
gl.camp.i <- lm(intolerance~gpc.Distance + gpc.prop_jewish25+gpc.unemployment33+gpc.population25+gpc.nazishare33 + 
                  MeanJewsC, data=evs)
tab_model(ri.gl.state.i,ri.gl.camp.i,ri.gl.state.camp.i,gl.state.i,gl.camp.i, gl.state.camp.i,
          show.se=TRUE, show.ci=FALSE, collapse.se=TRUE, show.p=FALSE, p.style="asterisk", p.threshold = c(0.05, 0.01))



#### GROUP-LEVEL PREDICTORS? WHERE ARE THE NAZIS? NOT THE PROBLEM (NOT REPORTED)

# DV: INTOLERANCE

ri.gl.state.i <- lmer(intolerance~gpc.Distance + gpc.prop_jewish25+gpc.unemployment33+gpc.population25+gpc.nazishare33 + 
                        MeanNazisS +
                        ( 1 | state) ,evs,
                      control = lmerControl(optimizer ="Nelder_Mead"))
ri.gl.camp.i <- lmer(intolerance~gpc.Distance + gpc.prop_jewish25+gpc.unemployment33+gpc.population25+gpc.nazishare33 + 
                       MeanNazisC +
                       ( 1 | closest_camp) ,evs,
                     control = lmerControl(optimizer ="Nelder_Mead"))
ri.gl.state.camp.i <- lmer(intolerance~gpc.Distance + gpc.prop_jewish25+gpc.unemployment33+gpc.population25+gpc.nazishare33 + 
                             MeanNazisS + MeanNazisC +
                             ( 1 | state) + ( 1 | closest_camp) ,evs,
                           control = lmerControl(optimizer ="Nelder_Mead"))
gl.state.camp.i <- lm(intolerance~gpc.Distance + gpc.prop_jewish25+gpc.unemployment33+gpc.population25+gpc.nazishare33 + 
                        MeanNazisS + MeanNazisC ,data=evs)
gl.state.i <- lm(intolerance~gpc.Distance + gpc.prop_jewish25+gpc.unemployment33+gpc.population25+gpc.nazishare33 + 
                   MeanNazisS, data=evs)
gl.camp.i <- lm(intolerance~gpc.Distance + gpc.prop_jewish25+gpc.unemployment33+gpc.population25+gpc.nazishare33 + 
                  MeanNazisC, data=evs)
tab_model(ri.gl.state.i,ri.gl.camp.i,ri.gl.state.camp.i,gl.state.camp.i,gl.state.i,gl.camp.i, 
          show.se=TRUE, show.ci=FALSE, collapse.se=TRUE, show.p=FALSE, p.style="asterisk", p.threshold = c(0.05, 0.01))



####### THE EFFECTS ARE DUE TO DIFFERENCES IN STATES BY DISTANCE

rs.gl.cl.state.camp.i <- lmer(intolerance~gpc.Distance*(MeanDistanceS+MeanDistanceC) + 
                                gpc.prop_jewish25+gpc.unemployment33+gpc.population25+gpc.nazishare33 + 
                                (1 + gpc.Distance| state) + (1 + gpc.Distance| closest_camp),evs,
                              control = lmerControl(optimizer ="Nelder_Mead")) 
p1 <- plot(Effect(c("gpc.Distance","MeanDistanceC"),
                  xlevels=list(gpc.Distance=10, MeanDistanceC=4), 
                  rs.gl.cl.state.camp.i), main="Random Effects: Camp")
p2 <- plot(Effect(c("gpc.Distance","MeanDistanceS"),
                  xlevels=list(gpc.Distance=10, MeanDistanceS=4), 
                  rs.gl.cl.state.camp.i), main="Random Effects: State")

gl.cl.state.camp.i <- lm(intolerance~gpc.Distance*(MeanDistanceS+MeanDistanceC) + 
                           gpc.prop_jewish25+gpc.unemployment33+gpc.population25+gpc.nazishare33 ,evs)
p3 <- plot(Effect(c("gpc.Distance","MeanDistanceC"),
                  xlevels=list(gpc.Distance=10, MeanDistanceC=4), 
                  gl.cl.state.camp.i), main="Pooled: Camp")
p4 <- plot(Effect(c("gpc.Distance","MeanDistanceS"),
                  xlevels=list(gpc.Distance=10, MeanDistanceS=4), 
                  gl.cl.state.camp.i), main="Pooled: State")

grid.arrange(p1,p2,p3,p4)
jpeg("figureS2.jpg", height=700, width=1000)
grid.arrange(p1, p2, p3, p4)
dev.off()

rs.gl.cl.state.camp.r <- lmer(resentment~gpc.Distance*(MeanDistanceS+MeanDistanceC) + 
                                gpc.prop_jewish25+gpc.unemployment33+gpc.population25+gpc.nazishare33 + 
                                (1 + gpc.Distance| state) + (1 + gpc.Distance| closest_camp),evs,
                              control = lmerControl(optimizer ="Nelder_Mead")) 
p1 <- plot(Effect(c("gpc.Distance","MeanDistanceC"),
                  xlevels=list(gpc.Distance=10, MeanDistanceC=4), 
                  rs.gl.cl.state.camp.r), main="Random Effects: Camp")
p2 <- plot(Effect(c("gpc.Distance","MeanDistanceS"),
                  xlevels=list(gpc.Distance=10, MeanDistanceS=4), 
                  rs.gl.cl.state.camp.r), main="Random Effects: State")

gl.cl.state.camp.r <- lm(resentment~gpc.Distance*(MeanDistanceS+MeanDistanceC) + 
                           gpc.prop_jewish25+gpc.unemployment33+gpc.population25+gpc.nazishare33 ,evs)
p3 <- plot(Effect(c("gpc.Distance","MeanDistanceC"),
                  xlevels=list(gpc.Distance=10, MeanDistanceC=4), 
                  gl.cl.state.camp.r), main="Pooled: Camp")
p4 <- plot(Effect(c("gpc.Distance","MeanDistanceS"),
                  xlevels=list(gpc.Distance=10, MeanDistanceS=4), 
                  gl.cl.state.camp.r), main="Pooled: State")

grid.arrange(p1,p2,p3,p4)
jpeg("figureS3.jpg", height=700, width=1000)
grid.arrange(p1, p2, p3, p4)
dev.off()


rs.gl.cl.state.camp.f <- lmer(far_right~gpc.Distance*(MeanDistanceS+MeanDistanceC) + 
                                gpc.prop_jewish25+gpc.unemployment33+gpc.population25+gpc.nazishare33 + 
                                (1 + gpc.Distance| state) + (1 + gpc.Distance| closest_camp),evs,
                              control = lmerControl(optimizer ="Nelder_Mead")) 
p1 <- plot(Effect(c("gpc.Distance","MeanDistanceC"),
                  xlevels=list(gpc.Distance=10, MeanDistanceC=4), 
                  rs.gl.cl.state.camp.f), main="Random Effects: Camp")
p2 <- plot(Effect(c("gpc.Distance","MeanDistanceS"),
                  xlevels=list(gpc.Distance=10, MeanDistanceS=4), 
                  rs.gl.cl.state.camp.f), main="Random Effects: State")

gl.cl.state.camp.f <- lm(far_right~gpc.Distance*(MeanDistanceS+MeanDistanceC) + 
                           gpc.prop_jewish25+gpc.unemployment33+gpc.population25+gpc.nazishare33 ,evs)
p3 <- plot(Effect(c("gpc.Distance","MeanDistanceC"),
                  xlevels=list(gpc.Distance=10, MeanDistanceC=4), 
                  gl.cl.state.camp.f), main="Pooled: Camp")
p4 <- plot(Effect(c("gpc.Distance","MeanDistanceS"),
                  xlevels=list(gpc.Distance=10, MeanDistanceS=4), 
                  gl.cl.state.camp.f), main="Pooled: State")

grid.arrange(p1,p2,p3,p4)
jpeg("figureS4.jpg", height=700, width=1000)
grid.arrange(p1, p2, p3, p4)
dev.off()

tab_model(rs.gl.cl.state.camp.i,gl.cl.state.camp.i, 
          rs.gl.cl.state.camp.r,gl.cl.state.camp.r,
          rs.gl.cl.state.camp.f,gl.cl.state.camp.f,
          show.se=TRUE, show.ci=FALSE, collapse.se=TRUE, show.p=FALSE, p.style="asterisk", p.threshold = c(0.05, 0.01),
          file="tableS11.html")



